package org.dg.iag.util;

import org.dg.iag.crawl.ExistFeedStore;
import org.dg.iag.crawl.TestFeedStore;
import org.dg.iag.crawl.interf.StoreInterface;
import org.dg.iag.dao.GenericDAO;
import org.dg.iag.dao.PutDAO;

public class StorageUtil {
	public static StoreInterface testFeedStore	= null;
	public static StoreInterface mainFeedStore	= null;
	
	/**
	 * 
	 * @param type "test" or "exist"
	 * @return
	 */
	public static StoreInterface getFeedStore(String type) {
		if ( "test".equals(type) ) {
			if ( testFeedStore == null ) {
				testFeedStore 		= new TestFeedStore();
			}
			return testFeedStore;
		}
		if ( "exist".equals(type) ) {
			if ( mainFeedStore == null ) {
				mainFeedStore 		= new ExistFeedStore();
			}
			return mainFeedStore;
		}
		return null;
	}
	
	/**
	 * 
	 * @param relLocalPath needs to include application collection(folder)
	 * @param rootTag
	 * @return
	 */
	public static boolean checkXmlExists(String relLocalPath, String rootTag) {
		GenericDAO<Object, Object> gdao	= new GenericDAO<Object, Object>(relLocalPath);
		String resultStr				= gdao.getElementsAsString();
		if (resultStr == null && rootTag != null && rootTag.length() >0 ) {
			PutDAO.putString(ApplicationConstants.APP_PATH + relLocalPath,rootTag );
			return true;
		}
		if (resultStr == null )
			return false;
		return true;
	}
}
